import { count, series, text, data } from '../services/home';

export default {
  namespace: 'home',

  state: {
    list: [],
    currentCount: [],
    currentSeries: [],
    currentText: [],
    currentData: [],
  },

  effects: {
    //数字列表
    *getcount(_, { call, put }) {
      const response = yield call(count);
      yield put({
        type: 'saveCurrentCount',
        payload: response,
      });
    },
    //折线图数据
    *getseries(_, { call, put }) {
      const response = yield call(series);
      yield put({
        type: 'saveCurrentSeries',
        payload: response,
      });
    },
    //人生感数据
    *gettext(_, { call, put }) {
      const response = yield call(text);
      yield put({
        type: 'saveCurrentText',
        payload: response,
      });
    },
    //表格数据
    *getdata(_, { call, put }) {
      const response = yield call(data);
      yield put({
        type: 'saveCurrentData',
        payload: response,
      });
    },
  },

  reducers: {
    saveCurrentCount(state, action) {
      return {
        ...state,
        currentCount: action.payload,
      };
    },
    saveCurrentSeries(state, action) {
      return {
        ...state,
        currentSeries: action.payload,
      };
    },
    saveCurrentText(state, action) {
      return {
        ...state,
        currentText: action.payload,
      };
    },
    saveCurrentData(state, action) {
      return {
        ...state,
        currentData: action.payload,
      };
    },
    changeNotifyCount(state, action) {
      return {
        ...state,
        currentCount: {
          ...state.currentCount,
          notifyCount: action.payload,
        },
        currentSeries: {
          ...state.currentSeries,
          notifyCount: action.payload,
        },
        currentText: {
          ...state.currentText,
          notifyCount: action.payload,
        },
        currentData: {
          ...state.currentData,
          notifyCount: action.payload,
        },
      };
    },
  },
};
